<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>

<%@ page import = "org.apache.struts.util.RequestUtils" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>

<bean:define id="micrositeNaviInfoParams" name="micrositeNaviInfoView" property="urlParams" scope="request" />

<script language="JavaScript">


<%--
function openwin(file) {
  var win = window.open(file , "NewWindow", 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=450,height=338');
  win.focus();
}

function onFileInputFocus()
{
  return document.csDocumentEditForm.newFile.focus();
}
--%>

//
// Trims leading blanks.
//
function stringLeftTrim(s)
{
   return s.replace(/^ +/, "");
}

//
// Trims trailing blanks.
//
function stringRightTrim(s)
{
   return s.replace(/ +$/, "");
}

//
// Trims leading and trailing blanks.
//
function stringTrim(s)
{
   return stringRightTrim(stringLeftTrim(s));
}

function validateForm(theForm) {
  var docName = stringTrim(theForm.name.value);
  
  if ( docName != null &&  docName == '' ) {
    alert('<bean:message key="cs.error.document.name"/>'); 
    return false;
  }

  if (docName.length > 80) {
    alert('<bean:message key="cs.error.document.name.tooLong" arg0="80" />'); 
    return false;
  }
 
  var docDesc = stringTrim(theForm.description.value);
  if (docDesc.length > 2000) {
    alert('<bean:message key="cs.error.description"/>'); 
    return false;
  }
 
  // Edit an existing document.
  if (theForm.ownerId.length == 0) {
    alert('<bean:message key="cs.error.document.owner"/>');
    return false;
  }

  var selectedOwner = theForm.ownerId.value;

  if (selectedOwner == -1 || selectedOwner == 0) {
    alert('<bean:message key="cs.error.document.owner"/>');
    return false;
  }
  
  var attachName = stringTrim(theForm.attName.value);
  var attachFile = stringTrim(theForm.attOriginalFileName.value);

  if (attachName != "" || attachFile != "") {
    alert('<bean:message key="cs.error.attachment.add.more"/>');
    return false;
  }
  theForm.name.value = docName; 
  return true;
}

function confirmDeleteDocument(theForm, url) {
  if ( confirm('<bean:message key="cs.confirm.delete.document"/>') ){
    theForm.action = url;
    theForm.submit();
  } else {
    return false;
  }
}


function onClickSave(theForm) { 

  if (validateForm(theForm)) {
    theForm.action = '<html:rewrite page="/cs/documentSave.do"/>';
    theForm.submit();
  }
  else {
    return false;
  }
}



//
// Create a dummy (timestamp) attribute to get around an IE cache problem.
//
function getTimeStamp() {
   var now = new Date;
   var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
   return timestamp;
}   


function selectOwnerPopup(theForm) {

  var popupURL = '<html:rewrite page="/cs/documentSelectOwner.do" name="micrositeNaviInfoParams" />';
  var timestamp = getTimeStamp();
  popupURL += '&timestamp=' + timestamp;

  var win = window.open('', "DocumentSelectOwner", "width=500,height=400,scrollbars=yes,resizable=yes");
  if ( win != null) {
    if( win.opener == null) {
      win.opener = self;
    }
  }
  win.focus();
  // save the current form setting so that it can be restored later
  var oldAction = theForm.action;
  var oldTarget = theForm.target;
  // submit the form to the popup so that we can pass the groupIds to the popup
  theForm.action = popupURL;
  theForm.target = "DocumentSelectOwner";   
  theForm.submit();
  theForm.action = oldAction;
  theForm.target = oldTarget;
}

function setOwner(selectedOwnerId, selectedOwnerName) {
  document.csDocumentEditForm.ownerId.value = selectedOwnerId;
  document.csDocumentEditForm.ownerName.value = selectedOwnerName;
}


</script>


<!-- Zone 5 starts here.  -->

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="content area">
  <tr>
    <td valign="top">
    
    <!--start microsite logo and name here-->
    <div class="pageTitle">
      <%@ include file="/cs/microsite/micrositeNaviInfo.jsp" %>
    </div> 
    <!--end microsite logo and name here-->

    <html:form action="/cs/documentSave.do" method="post">

    <!--start title bar here-->
    <div class="pageSubtitle">
    
      <%-- If the documentId == 0, this is a "Create New Document" page, --%>
      <%-- Otherwise, this is an "Edit" document page.  --%>
      <logic:equal name="csDocumentEditForm" property="documentId" value="0">
      <span class="left">
        <bean:message key="cs.document.create.new"/>
      </span>          
      </logic:equal>
 
      <logic:notEqual name="csDocumentEditForm" property="documentId" value="0">
      <span class="left">    
         <bean:define id="docViewName" name="csDocumentEditForm" property="name"/>      
         <%String docName = docViewName.toString();%>
         <bean:message key="cs.edit" arg0="<%=docName %>"/> 
      </span>
      <span class="right">
	&nbsp;
      </span>          
      </logic:notEqual>
      
    </div>
    <!--end title bar here--> 
    
    <div class="blockWrap">
       
    <!-- Display Document info -->
    
    <!-- start Page Instructions -->
    <div class="pageInstructions">
      <bean:message key="cs.document.edit.note"/>
    </div>
    <!-- End Page Instructions -->
   
    <!--start main content area here-->
    <table class="labelForm" width="100%" border="0" cellspacing="0" 
           cellpadding="0" summary="Edit Group">
         
      <%-- document name --%>
      <tr> 
        <td nowrap width="20%" class="label">
          <bean:message key="cs.document.name"/>*:<br>
        </td>
        <td width="80%" class="labelField" nowrap>
          <html:text property="name" size="30" maxlength="80"/>
        </td>
      </tr>

      <%-- document description --%>
      <tr> 
        <td nowrap width="20%" class="label"> 
          <bean:message key="cs.description"/>:  
        </td>
        <td width="80%" class="labelField" nowrap>
          <html:textarea property="description" cols="30" rows="5"/>
        </td>
      </tr>

      <%-- phase name (if phaseFlag is true) --%>
      <logic:equal name="documentEditView" property="phaseFlag" value="true">
      <tr> 
        <td nowrap width="20%" class="label">
          <bean:message key="cs.phase"/>:
        </td>
        <td width="80%" class="labelField" nowrap>
          <bean:write name="documentEditView" property="phaseName"/>
        </td>
      </tr>
      </logic:equal>

      <%-- owners selection --%>
      <tr> 
        <td nowrap width="20%" class="label">
          <bean:message key="cs.owner"/>*:
        </td>
        <td width="80%" class="labelField" nowrap>
          <html:text name="csDocumentEditForm" property="ownerName" readonly="true"/>
          <input type="hidden" name="ownerId" value=<bean:write name="csDocumentEditForm" property="ownerId"/> >
          <html:button property="selectOwner" onclick="selectOwnerPopup(this.form)" styleClass="inputButton">
            <bean:message key="cs.button.select.owner"/>
          </html:button>
        </td>
      </tr>
    </table>
    <!--end main content area here-->

    <!-- Start Display attachment. -->
    <script language="JavaScript">
      var nextPage = '<html:rewrite page="/cs/documentAttachmentAdd.do"/>';
      var attachmentDeleteAction = '<html:rewrite page="/cs/documentAttachmentDelete.do" />';

      <logic:equal name="csDocumentEditForm" property="documentId" value="0">
        var nextActionAfterCancel = '/cs/documentIndex.do';
        var nextActionAfterReset = '/cs/documentNew.do';
      </logic:equal>
      <logic:notEqual name="csDocumentEditForm" property="documentId" value="0">
        var nextActionAfterCancel = '/cs/documentView.do';
        var nextActionAfterReset = '/cs/documentEdit.do';
      </logic:notEqual>
    </script>
    <bean:define id="formBeanUsed" name="csDocumentEditForm" toScope="request" />
    <%@ include file="/cs/microsite/attachment/attachmentEdit.jsp" %>
    <!-- end of attachments secion -->

    <!--start reset, cancel, save buttons bar area here-->
    <div class="pageButtonWrap" align="right">
      <%-- onclick event handler resetAttachment() is in attachmentEdit.jsp. --%>
      <html:button styleClass="pageButton" property="resetBtn" 
                   titleKey="button.reset" onclick="return resetAttachment(this.form)">
        <bean:message key="button.reset"/>
      </html:button>
	&nbsp;&nbsp;
      <%-- onclick event handler cancelClearAttachment() is in attachmentEdit.jsp. --%>
      <html:button styleClass="pageButton" property="cancelBtn" 
                   titleKey="button.cancel" onclick="return cancelClearAttachment(this.form)">
        <bean:message key="button.cancel"/>
      </html:button>
                 
      <html:button styleClass="pageButton" property="saveBtn" 
            titleKey="button.save" onclick="onClickSave(this.form)">
        <bean:message key="button.save"/>
      </html:button>
    </div>
    <!--end reset, cancel, save bar area here-->

    <%-- list of hidden fields to be submitted. --%>
    <bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>
    <html:hidden name="csDocumentEditForm" property="sequenceKey"/>  
     
    </html:form>
   
    </div>
    </td>
  </tr>
</table>

<!--end zone 5 content here -->  

